package com.sg.service.biz.app.impl;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.app.req.AnalysisIntegrateThemeContInfoComReqDto;
import com.sg.dto.biz.app.req.ImplementElevenReceivingFieldReqDto;
import com.sg.dto.biz.app.res.AnalysisIntegrateThemeContInfoComRespDto;
import com.sg.dto.biz.app.res.ImplementElevenReceivingFieldRespDto;
import com.sg.dto.integration.framework.QueryDeptDetailComBorderReqDto;
import com.sg.dto.integration.framework.QueryDeptDetailComBorderRespDto;
import com.sg.dto.integration.framework.QuerySpaceDetailComReqDto;
import com.sg.dto.integration.framework.QuerySpaceDetailComRespDto;
import com.sg.service.base.app.MOmsExecuteCycleStageService;
import com.sg.common.exception.Assert;
import com.wicket.okrframework.integration.BaseService;
import com.wicket.okrframework.integration.OrgService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class CrossTempIntegrateServiceImpl
        implements com.wicket.okrapp.biz.service.CrossTempIntegrateService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MOmsExecuteCycleStageService mOmsExecuteCycleStageService;
    @Resource
    private NbCrossTempIntegrate nbCrossTempIntegrate;
    @Resource
    private BaseService baseService;
    @Resource
    private OrgService orgService;

    /**
     * D3分析整合主题内容信息(公共)[10133]
     * gen by moon at 8/21/2024, 12:16:05 PM
     */
    @Trace(operationName = "D3分析整合主题内容信息(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AnalysisIntegrateThemeContInfoComRespDto analysisIntegrateThemeContInfoCom(AnalysisIntegrateThemeContInfoComReqDto reqDto) {


        ImplementElevenReceivingFieldRespDto receptionServiceRes_1 = null;
        if ((reqDto != null && reqDto.getIntegrateThemeContType() != null && reqDto.getIntegrateThemeContType().equals("OMS_ORG_ORGANIZATION"))) {
            //if(D3分析整合主题内容信息(公共).整合主题内容类型编码 等于 组织表)  72396

            QuerySpaceDetailComRespDto querySpaceDetailComRespDto = null;
            QuerySpaceDetailComReqDto querySpaceDetailComReqDto = new QuerySpaceDetailComReqDto();

            querySpaceDetailComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//SimpleFieldAssign//sourceId:1980290_1_72398


            /*D1-2查空间详情(公共)[402]   */
            Assert.isNull(querySpaceDetailComReqDto.getSpaceId(), "D3分析整合主题内容信息(公共)-D1-2查空间详情(公共)-空间ID不能为空", false);
            querySpaceDetailComRespDto = baseService.querySpaceDetailCom(querySpaceDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//ModelCode: receptionService
            ImplementElevenReceivingFieldRespDto receptionServiceRes = null;
            if (querySpaceDetailComRespDto != null) {
                ImplementElevenReceivingFieldReqDto receptionServiceReq = new ImplementElevenReceivingFieldReqDto();
                if (querySpaceDetailComRespDto != null) {
                    receptionServiceReq.setIntegrateThemeContName(querySpaceDetailComRespDto.getAbbreviation());//SimpleFieldAssign//sourceId:1980756_1_72400
                }

                /*M3接收整合主题内容名称出参[9482]  用于特殊方法接收上游入参。 */
                Assert.isNull(receptionServiceReq.getIntegrateThemeContName(), "D3分析整合主题内容信息(公共)-M3接收整合主题内容名称出参-整合主题内容名称不能为空", false);
                receptionServiceRes = nbCrossTempIntegrate.implementElevenReceivingField(receptionServiceReq);


                receptionServiceRes_1 = receptionServiceRes;
            }
        } else if ((reqDto != null && reqDto.getIntegrateThemeContType() != null && reqDto.getIntegrateThemeContType().equals("OMS_ORG_DEPT"))) {
            //elseif(D3分析整合主题内容信息(公共).整合主题内容类型编码 等于 部门表)  72397

            QueryDeptDetailComBorderRespDto queryDeptDetailComBorderRespDto = null;
            QueryDeptDetailComBorderReqDto queryDeptDetailComBorderReqDto = new QueryDeptDetailComBorderReqDto();
            if (reqDto != null) {
                queryDeptDetailComBorderReqDto.setDeptId(reqDto.getIntegrateThemeContId());//SimpleFieldAssign//sourceId:1980316_1_72399
            }

            /*D1-3查询部门详情(公共)(边界)[2691]   */
            Assert.isNull(queryDeptDetailComBorderReqDto.getDeptId(), "D3分析整合主题内容信息(公共)-D1-3查询部门详情(公共)(边界)-部门ID不能为空", false);
            queryDeptDetailComBorderRespDto = orgService.queryDeptDetailComBorder(queryDeptDetailComBorderReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//ModelCode: receptionService
            ImplementElevenReceivingFieldRespDto receptionServiceRes_2 = null;
            if (queryDeptDetailComBorderRespDto != null) {
                ImplementElevenReceivingFieldReqDto receptionServiceReq_1 = new ImplementElevenReceivingFieldReqDto();
                if (queryDeptDetailComBorderRespDto != null) {
                    receptionServiceReq_1.setIntegrateThemeContName(queryDeptDetailComBorderRespDto.getDeptShortName());//SimpleFieldAssign//sourceId:1980756_1_72401
                }

                /*M3接收整合主题内容名称出参[9482]  用于特殊方法接收上游入参。 */
                Assert.isNull(receptionServiceReq_1.getIntegrateThemeContName(), "D3分析整合主题内容信息(公共)-M3接收整合主题内容名称出参-整合主题内容名称不能为空", false);
                receptionServiceRes_2 = nbCrossTempIntegrate.implementElevenReceivingField(receptionServiceReq_1);


                receptionServiceRes_1 = receptionServiceRes_2;
            }
        }
        AnalysisIntegrateThemeContInfoComRespDto retData = new AnalysisIntegrateThemeContInfoComRespDto();
        if (receptionServiceRes_1 != null) {
            retData.setIntegrateThemeContName(receptionServiceRes_1.getIntegrateThemeContName());//SimpleFieldAssign//sourceId:1980758_1
        }


        return retData;
    }
    //
}
